home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 2.9 KB | 139 lines | [TEXT/MPS ] |
- /*
- File: TestNoVTable.cp
-
- Contains: Implementation of class TTestNoVTable
-
- Copyright: © 1992-1994 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #ifndef __TESTNOVTABLE__
- #include "TestNoVTable.h"
- #endif
- #ifndef __MISCTESTS__
- #include "MiscTests.h"
- #endif
-
- static TNoVTable gTemp(7);
- static TStdVTable gStdTemp(25);
-
- TTestNoVTable::TTestNoVTable()
- {}
-
- TTestNoVTable::~TTestNoVTable()
- {}
-
- void TTestNoVTable::InitTest(BooleanParm, BooleanParm, int, char**)
- {}
-
- void TTestNoVTable::EndTest(BooleanParm, BooleanParm)
- {}
-
- void TTestNoVTable::RunTestIteration(BooleanParm verbose, BooleanParm debug)
- {
- Boolean ok = true;
- unsigned long elapsed;
-
- if (verbose)
- Printf("### INFO: Testing static object with no VTable\n");
- long val = gTemp.Add(4);
- if (val != 11)
- {
- Printf("### ERROR: Expected 11 from Add, got %ld\n", val);
- }
- if (verbose)
- Printf("### INFO: Testing auto object with no VTable\n");
- {
- TNoVTable test(5);
-
- val = test.Add(4);
- if (val != 9)
- {
- ok = false;
- Printf("### ERROR: Expected 9 from TNoVTable::Add, got %ld\n", val);
- }
- val = test.Sub(7);
- if (val != 2)
- {
- ok = false;
- Printf("### ERROR: Expected 2 from TNoVTable::Sub, got %ld\n", val);
- }
- if (ok)
- {
- TStopwatch theStamp;
- for (size_t idx = 0; idx < 1000; ++idx)
- {
- val = test.Add(0);
- }
- elapsed = (&theStamp)->ElapsedMicroseconds();
- }
- }
- if (ok)
- Printf("### INFO: 1000 iterations for TNoVTable took %lu microseconds\n", elapsed);
-
- if (debug)
- DebugBreak("About to test TStdVTable");
-
- if (verbose)
- Printf("### INFO: Testing static object with standard VTable\n");
- val = gStdTemp.Add(4);
- if (val != 29)
- {
- Printf("### ERROR: Expected 29 from TStdVTable::Add, got %ld\n", val);
- }
- if (verbose)
- Printf("### INFO: Testing auto object with standard VTable\n");
- {
- TStdVTable test(9);
- val = (&test)->Add(4);
- if (val != 13)
- {
- ok = false;
- Printf("### ERROR: Expected 13 from TStdVTable::Add, got %ld\n", val);
- }
- val = (&test)->Sub(7);
- if (val != 6)
- {
- ok = false;
- Printf("### ERROR: Expected 6 from TStdVTable::Sub, got %ld\n", val);
- }
- if (ok)
- {
- TStopwatch theStamp;
- for (size_t idx = 0; idx < 1000; ++idx)
- {
- val = (&test)->Add(0);
- }
- elapsed = (&theStamp)->ElapsedMicroseconds();
- }
- if (ok)
- Printf("### INFO: 1000 iterations for TStdObject through the vtable took %lu microseconds\n", elapsed);
- }
- {
- TStdVTable test(11);
- val = test.Add(4);
- if (val != 15)
- {
- ok = false;
- Printf("### ERROR: Expected 15 from TStdVTable::Add, got %ld\n", val);
- }
- val = test.Sub(7);
- if (val != 8)
- {
- ok = false;
- Printf("### ERROR: Expected 8 from TStdVTable::Sub, got %ld\n", val);
- }
- if (ok)
- {
- TStopwatch theStamp;
- for (size_t idx = 0; idx < 1000; ++idx)
- {
- val = test.Add(0);
- }
- elapsed = (&theStamp)->ElapsedMicroseconds();
- }
- if (ok)
- Printf("### INFO: 1000 iterations for TStdObject through stubs took %lu microseconds\n", elapsed);
- }
- }
-